<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jstl/core">

<ui:composition>
    <div class="mainMenu">
        <ul>
            <li class="#{selectedMenu eq 'sell' ? 'selectedMenu' : ''}">
                <h:outputLink value="#{ctxPath}/content/pages/sell/viewAdverts.xhtml?advert-type=S">
                    #{labels['SELLING']}
                </h:outputLink>                
                <h:panelGroup layout="block" styleClass="mainMenuSub1" rendered="#{selectedMenu eq 'sell'}">
                    <ul>
                        <ui:repeat value="#{productTypes}" var="prdType">
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/sell/viewAdverts.xhtml?advert-type=S&#38;product-type=#{prdType.name()}"
                                            styleClass="#{productType eq prdType.name() ? 'selectedMenuItem' : ''}">
                                            #{labels[prdType.label]}
                                </h:outputLink>
                                <h:panelGroup layout="block" styleClass="mainMenuSub2" rendered="#{productType eq prdType.name()}">
                                    <ul>
                                        <ui:repeat value="#{vehicleTypes}" var="vclType">
                                            <li>
                                                <h:outputLink value="#{ctxPath}/content/pages/sell/viewAdverts.xhtml?advert-type=S&#38;product-type=#{prdType.name()}&#38;vehicle-type=#{vclType.code}"
                                                            styleClass="#{vehicleType eq vclType.code ? 'selectedMenuItem' : ''}">
                                                            #{labels[vclType.name]}
                                                </h:outputLink>
                                                <h:panelGroup layout="block" styleClass="mainMenuSub3" rendered="#{vehicleType eq vclType.code}">
                                                    <ul>
                                                        <ui:repeat value="#{vehicleCategories.get(vehicleType)}" var="vclCategory">
                                                            <li>
                                                                <h:outputLink value="#{ctxPath}/content/pages/sell/viewAdverts.xhtml?advert-type=S&#38;product-type=#{prdType.name()}&#38;vehicle-type=#{vclType.code}&#38;vehicle-ctgr=#{vclCategory.code}"
                                                                            styleClass="#{vehicleCategory eq vclCategory.code ? 'selectedMenuItem' : ''}">
                                                                            #{labels[vclCategory.name]}
                                                                </h:outputLink>

                                                            </li>
                                                        </ui:repeat>
                                                    </ul>
                                                </h:panelGroup>
                                            </li>
                                        </ui:repeat>
                                    </ul>
                                </h:panelGroup>
                            </li>
                        </ui:repeat>
                    </ul>
                </h:panelGroup>
            </li>
            <ui:remove>
            <!--li class="#{selectedMenu eq 'buy' ? 'selectedMenu' : ''}">
                <h:outputLink value="#{ctxPath}/content/pages/buy/viewAdverts.xhtml">
                    #{labels['BUYING']}
                </h:outputLink>
            </li>-->
            </ui:remove>
            <h:panelGroup rendered="#{SecurityManager.loggedIn}">
                <li class="#{selectedMenu eq 'mymenu' ? 'selectedMenu' : ''}">
                    <h:outputLink value="#{ctxPath}/content/pages/mymenu/myAdverts.xhtml">
                        #{labels['MY_MENU']}
                    </h:outputLink>

                    <h:panelGroup layout="block" styleClass="mainMenuSub1" rendered="#{selectedMenu eq 'mymenu'}">
                        <ul>
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/mymenu/myAdverts.xhtml"
                                            styleClass="#{selectedMenuSub1 eq 'adverts' ? 'selectedMenuItem' : ''}">
                                            #{labels['MY_ADVERTS']}
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/mymenu/aboutMeView.xhtml"
                                            styleClass="#{selectedMenuSub1 eq 'profile' ? 'selectedMenuItem' : ''}">
                                            #{labels['ABOUT_ME']}
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/mymenu/changePassword.xhtml"
                                            styleClass="#{selectedMenuSub1 eq 'password' ? 'selectedMenuItem' : ''}">
                                            #{labels['CHANGE_PASSWORD']}
                                </h:outputLink>
                            </li>
                        </ul>
                    </h:panelGroup>
                </li>
            </h:panelGroup>
            <h:panelGroup rendered="#{SecurityManager.isUserInRole('ADMIN')}">
                <li class="#{selectedMenu eq 'admin' ? 'selectedMenu' : ''}">
                    <h:outputLink value="#{ctxPath}/content/pages/admin/adverts.xhtml">
                        #{labels['ADMIN']}
                    </h:outputLink>

                    <h:panelGroup layout="block" styleClass="mainMenuSub1" rendered="#{selectedMenu eq 'admin'}">
                        <ul>
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/admin/adverts.xhtml"
                                            styleClass="#{selectedMenuSub1 eq 'adverts' ? 'selectedMenuItem' : ''}">
                                            #{labels['ADVERTS']}
                                </h:outputLink>
                            </li>
                            <li>
                                <h:outputLink value="#{ctxPath}/content/pages/admin/users.xhtml?role=#{userRoles[0]}"
                                            styleClass="#{selectedMenuSub1 eq 'users' ? 'selectedMenuItem' : ''}">
                                            #{labels['USERS']}
                                </h:outputLink>
                                <h:panelGroup rendered="#{selectedMenuSub1 eq 'users'}" styleClass="mainMenuSub2">
                                    <ul>
                                        <ui:repeat value="#{userRoles}" var="role">
                                            <li>
                                                <h:outputLink value="#{ctxPath}/content/pages/admin/users.xhtml?role=#{role}"
                                                            styleClass="#{role eq userRole ? 'selectedMenuItem' : ''}">
                                                            #{labels[role.name()]}
                                                </h:outputLink>
                                            </li>
                                        </ui:repeat>
                                    </ul>
                                </h:panelGroup>
                            </li>
                        </ul>
                    </h:panelGroup>
                </li>
            </h:panelGroup>
        </ul>
    </div>

    <h:panelGroup layout="block">
        <ui:include src="/content/components/authLinksComponent.xhtml"/>
    </h:panelGroup>
    
    <h:panelGroup layout="block" id="addAdvertPanel">
        <ul>
            <li>
                <h:outputLink value="#{ctxPath}/content/pages/sell/addAdvert.xhtml">#{labels['ADD_NEW_ADVERT']}</h:outputLink>
            </li>
        </ul>
    </h:panelGroup>

</ui:composition>

</html>